﻿using System;
using System.Buffers;
using System.Linq;
namespace Xc.DataAccess.PcpChannels
{
    /// <summary>
    /// 新版本通知应答
    /// </summary>
    public class CloundNewVersionNotifyRespond : RespondFrame
    {
        public CloundNewVersionNotifyRespond(byte[] dataarea) : base(dataarea)
        {

        }
        
        protected override MessageCode? ValidateMessageCode => MessageCode.NewVersionNotify;
        /// <summary>
        /// 新版本状态
        /// </summary>
        public NewVersionNotify Status { get;private set; }
        /// <summary>
        /// 新版本通知
        /// </summary>
        public enum NewVersionNotify
        {
            /// <summary>
            /// 允许升级
            /// </summary>
            AllowUpdate=0x00,
            /// <summary>
            /// 设备使用中
            /// </summary>
            DeviceOnUse=0x01,
            /// <summary>
            /// 信号质量差
            /// </summary>
            SignalQualityBad=0x02,
            /// <summary>
            /// 已是最新版本
            /// </summary>
            AlreadyLatest=0x03,
            /// <summary>
            /// 电量不足
            /// </summary>
            VoltageLow=0x04,
            /// <summary>
            /// 剩余空间不足
            /// </summary>
            SpaceInsufficient=0x05,
            /// <summary>
            /// 内存不足
            /// </summary>
            OutOfMemory=0x09,
            /// <summary>
            /// 内部异常
            /// </summary>
            InnerException=0x7F
        }

        protected override bool SetDataArea(ref SequenceReader<byte> dataArea)
        {
            if (dataArea.TryRead(out var c))
            {
                Status = (NewVersionNotify)c;
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
